#!/data/data/com.termux/files/usr/bin/bash


GLOBAL_WIDTH=$(stty size | awk '{printf("%d", $2)}')
strlen(){
	str=`echo "$1" | sed 's/[ ]/_/g'`
	strlen=${#str}
	str1=`echo $str | tr -cd "[!-~]" `
	strlen1=${#str1}
	resultlen=`echo $strlen $strlen1 | awk '{printf("%d",($1-($1-$2)/3))}'`
	echo $resultlen
}



printCenter() {
	if [ ! "$1" ]; then
		char=" "
	else
		char="$1"
	fi
	if [ ! "$2" ]; then
		shellwidth=$(stty size | awk '{printf("%d", $2)}')
		yes "$char" | sed $shellwidth'q' | tr -d '\n'
		return 0;
	fi
	len=$(strlen "$2")
	space=$(echo $GLOBAL_WIDTH $len | awk '{printf("%d",($1-$2-1)/2)}')
	printf "$char"
	if test $space -gt 0 ; then
		yes " " | sed $space'q' | tr -d '\n'
	fi
	printf "$2"
	space=$(echo $GLOBAL_WIDTH $len $space | awk '{printf("%d",$1-$2-$3-2)}')
	if test $space -gt 0 ; then
		yes " " | sed $space'q' | tr -d '\n'
	fi
	printf "$char\n"
}



printLeft() {
	if [ ! "$1" ]; then
		char=" "
	else
		char="$1"
	fi
	len=$(strlen "$2")
	space=$(echo $GLOBAL_WIDTH $len | awk '{printf("%d",($1-$2-1)/2)}')
	printf "$char"
	space=0
	if test $space -gt 0 ; then
		yes " " | sed $space'q' | tr -d '\n'
	fi
	printf "$2"
	space=$(echo $GLOBAL_WIDTH $len $space | awk '{printf("%d",$1-$2-$3-2)}')
	if test $space -gt 0 ; then
		yes " " | sed $space'q' | tr -d '\n'
	fi
	printf "$char\n"
}